﻿using System;
using System.Collections.Generic;

namespace UnityEngine
{
	// Token: 0x020000F8 RID: 248
	public class SubdivideMesh
	{
		// Token: 0x06000575 RID: 1397 RVA: 0x00021C20 File Offset: 0x0001FE20
		public static int GetNewVertex(int i1, int i2)
		{
			uint key = (uint)(i1 << 16 | i2);
			uint key2 = (uint)(i2 << 16 | i1);
			if (SubdivideMesh.newVectices.ContainsKey(key2))
			{
				return SubdivideMesh.newVectices[key2];
			}
			if (SubdivideMesh.newVectices.ContainsKey(key))
			{
				return SubdivideMesh.newVectices[key];
			}
			int count = SubdivideMesh.vertices.Count;
			SubdivideMesh.newVectices.Add(key, count);
			SubdivideMesh.vertices.Add((SubdivideMesh.vertices[i1] + SubdivideMesh.vertices[i2]) * 0.5f);
			SubdivideMesh.normals.Add((SubdivideMesh.normals[i1] + SubdivideMesh.normals[i2]).normalized);
			return count;
		}

		// Token: 0x06000576 RID: 1398 RVA: 0x00021CE8 File Offset: 0x0001FEE8
		public static void Subdivide(Mesh mesh)
		{
			SubdivideMesh.newVectices = new Dictionary<uint, int>();
			SubdivideMesh.vertices = new List<Vector3>(mesh.vertices);
			SubdivideMesh.normals = new List<Vector3>(mesh.normals);
			SubdivideMesh.indices = new List<int>();
			int[] triangles = mesh.triangles;
			for (int i = 0; i < triangles.Length; i += 3)
			{
				int num = triangles[i];
				int num2 = triangles[i + 1];
				int num3 = triangles[i + 2];
				int newVertex = SubdivideMesh.GetNewVertex(num, num2);
				int newVertex2 = SubdivideMesh.GetNewVertex(num2, num3);
				int newVertex3 = SubdivideMesh.GetNewVertex(num3, num);
				SubdivideMesh.indices.Add(num);
				SubdivideMesh.indices.Add(newVertex);
				SubdivideMesh.indices.Add(newVertex3);
				SubdivideMesh.indices.Add(num2);
				SubdivideMesh.indices.Add(newVertex2);
				SubdivideMesh.indices.Add(newVertex);
				SubdivideMesh.indices.Add(num3);
				SubdivideMesh.indices.Add(newVertex3);
				SubdivideMesh.indices.Add(newVertex2);
				SubdivideMesh.indices.Add(newVertex);
				SubdivideMesh.indices.Add(newVertex2);
				SubdivideMesh.indices.Add(newVertex3);
			}
			mesh.vertices = SubdivideMesh.vertices.ToArray();
			mesh.normals = SubdivideMesh.normals.ToArray();
			mesh.triangles = SubdivideMesh.indices.ToArray();
			SubdivideMesh.newVectices = null;
			SubdivideMesh.vertices = null;
			SubdivideMesh.normals = null;
			SubdivideMesh.indices = null;
		}

		// Token: 0x0400058E RID: 1422
		public static List<Vector3> vertices;

		// Token: 0x0400058F RID: 1423
		public static List<Vector3> normals;

		// Token: 0x04000590 RID: 1424
		public static List<int> indices;

		// Token: 0x04000591 RID: 1425
		public static Dictionary<uint, int> newVectices;
	}
}
